package com.zoe.onelink.test.container.redis.util;

import com.zoe.onelink.redis.autoconfigure.RedisTemplateAutoConfiguration;
import com.zoe.onelink.redis.util.RedisUtil;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2021</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2021-11-19
 */
public class RedisTestUtilInit {

    public static void init(String host, String password, int port, int database) throws Exception {

        RedisTemplateAutoConfiguration redisTemplateAutoConfiguration = new RedisTemplateAutoConfiguration();
        RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
        configuration.setHostName(host);
        configuration.setPort(port);
        configuration.setPassword(password);
        configuration.setDatabase(database);
        LettuceConnectionFactory redisConnectionFactory = new LettuceConnectionFactory(configuration, LettuceClientConfiguration.defaultConfiguration());
        redisConnectionFactory.afterPropertiesSet();
        RedisTemplate<String, Object> redisTemplate = redisTemplateAutoConfiguration.redisTemplate(redisConnectionFactory);
        StringRedisTemplate stringRedisTemplate = redisTemplateAutoConfiguration.stringRedisTemplate(redisConnectionFactory);
        RedisUtil redisUtil = new RedisUtil(redisTemplate, stringRedisTemplate);
        redisUtil.afterPropertiesSet();

    }
}
